<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>RPC框架设计指南</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 30px;
            background: linear-gradient(to bottom, #667eea, #764ba2);
            border-radius: 2px;
        }
        
        .feature-icon {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
        
        .highlight-box {
            background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
            border-left: 4px solid #667eea;
            padding: 1.5rem;
            margin: 1.5rem 0;
            border-radius: 0 8px 8px 0;
        }
        
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .animate-fadeInUp {
            animation: fadeInUp 0.8s ease-out;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-6">
        <div class="max-w-6xl mx-auto text-center animate-fadeInUp">
            <h1 class="text-5xl md:text-6xl font-bold mb-6">
                <i class="fas fa-network-wired mr-4"></i>RPC框架设计指南
            </h1>
            <p class="text-xl md:text-2xl mb-8 opacity-90">构建高效、灵活的分布式通信基础设施</p>
            <div class="flex justify-center space-x-6 text-lg">
                <span><i class="fas fa-layer-group mr-2"></i>架构设计</span>
                <span><i class="fas fa-cogs mr-2"></i>核心组件</span>
                <span><i class="fas fa-chart-line mr-2"></i>性能优化</span>
            </div>
        </div>
    </section>

    <!-- Introduction -->
    <section class="max-w-6xl mx-auto px-6 py-16">
        <div class="bg-white rounded-2xl shadow-xl p-8 md:p-12 card-hover">
            <p class="text-lg leading-relaxed text-gray-700">
                <span class="drop-cap">设</span>计一个高效、灵活的 RPC 框架需要考虑多个方面，从网络通信协议到服务治理，再到开发者体验。本指南将深入探讨如何构建一个现代化的 RPC 框架，涵盖从整体架构到具体实现的各个关键环节。
            </p>
        </div>
    </section>

    <!-- Architecture Overview -->
    <section class="max-w-6xl mx-auto px-6 py-8">
        <h2 class="text-4xl font-bold mb-12 text-center text-gray-800">
            <i class="fas fa-sitemap mr-3 feature-icon"></i>整体架构设计
        </h2>
        
        <div class="grid md:grid-cols-2 gap-8 mb-12">
            <div class="bg-white rounded-xl shadow-lg p-8 card-hover">
                <div class="flex items-center mb-4">
                    <i class="fas fa-exchange-alt text-3xl feature-icon mr-4"></i>
                    <h3 class="text-2xl font-bold text-gray-800">客户端和服务端</h3>
                </div>
                <p class="text-gray-600 leading-relaxed">RPC 框架的核心是客户端和服务端的通信。客户端发起远程调用请求，服务端接收请求并处理，然后将结果返回给客户端。</p>
            </div>
            
            <div class="bg-white rounded-xl shadow-lg p-8 card-hover">
                <div class="flex items-center mb-4">
                    <i class="fas fa-satellite-dish text-3xl feature-icon mr-4"></i>
                    <h3 class="text-2xl font-bold text-gray-800">通信协议</h3>
                </div>
                <p class="text-gray-600 leading-relaxed">选择合适的通信协议，如 TCP、HTTP/2 等。需要考虑传输的效率、可靠性、以及支持的功能（如流式传输、双向通信等）。</p>
            </div>
            
            <div class="bg-white rounded-xl shadow-lg p-8 card-hover">
                <div class="flex items-center mb-4">
                    <i class="fas fa-file-code text-3xl feature-icon mr-4"></i>
                    <h3 class="text-2xl font-bold text-gray-800">序列化/反序列化</h3>
                </div>
                <p class="text-gray-600 leading-relaxed">为了在网络上传输数据，需将请求和响应对象序列化为字节流，并在接收端反序列化。可以选择 Protobuf、Thrift 等高效的二进制序列化方式。</p>
            </div>
            
            <div class="bg-white rounded-xl shadow-lg p-8 card-hover">
                <div class="flex items-center mb-4">
                    <i class="fas fa-search-location text-3xl feature-icon mr-4"></i>
                    <h3 class="text-2xl font-bold text-gray-800">服务注册与发现</h3>
                </div>
                <p class="text-gray-600 leading-relaxed">分布式环境中，服务实例可能动态增减，需要一个服务注册中心来管理服务的注册和发现，确保客户端能够准确定位服务。</p>
            </div>
        </div>

        <!-- Architecture Diagram -->
        <div class="bg-white rounded-xl shadow-lg p-8">
            <h3 class="text-2xl font-bold mb-6 text-center text-gray-800">RPC框架架构图</h3>
            <div class="mermaid">
                graph TB
                    subgraph 客户端
                        A[应用层] --> B[代理层]
                        B --> C[序列化层]
                        C --> D[网络传输层]
                    end
                    
                    subgraph 服务端
                        E[网络传输层] --> F[反序列化层]
                        F --> G[服务实现层]
                        G --> H[应用层]
                    end
                    
                    subgraph 服务治理
                        I[服务注册中心]
                        J[负载均衡]
                        K[熔断器]
                        L[监控中心]
                    end
                    
                    D -.-> E
                    B -.-> I
                    B -.-> J
                    B -.-> K
                    D -.-> L
                    E -.-> L
            </div>
        </div>
    </section>

    <!-- Detailed Design -->
    <section class="max-w-6xl mx-auto px-6 py-16">
        <h2 class="text-4xl font-bold mb-12 text-center text-gray-800">
            <i class="fas fa-drafting-compass mr-3 feature-icon"></i>详细设计
        </h2>

        <!-- Communication Layer -->
        <div class="mb-16">
            <h3 class="section-title text-3xl font-bold mb-8 text-gray-800">通信层设计</h3>
            <div class="grid md:grid-cols-3 gap-6">
                <div class="highlight-box">
                    <h4 class="font-bold text-lg mb-2 text-gray-800"><i class="fas fa-protocol mr-2"></i>选择协议</h4>
                    <p class="text-gray-600">采用 HTTP/2 协议，支持双向流、头部压缩和多路复用，提高传输效率。</p>
                </div>
                <div class="highlight-box">
                    <h4 class="font-bold text-lg mb-2 text-gray-800"><i class="fas fa-link mr-2"></i>连接管理</h4>
                    <p class="text-gray-600">实现连接池和长连接管理，减少连接建立和释放的开销，支持高并发调用。</p>
                </div>
                <div class="highlight-box">
                    <h4 class="font-bold text-lg mb-2 text-gray-800"><i class="fas fa-balance-scale mr-2"></i>负载均衡</h4>
                    <p class="text-gray-600">在客户端集成负载均衡策略，如轮询、随机、加权轮询等。</p>
                </div>
            </div>
        </div>

        <!-- Serialization -->
        <div class="mb-16">
            <h3 class="section-title text-3xl font-bold mb-8 text-gray-800">序列化/反序列化</h3>
            <div class="bg-white rounded-xl shadow-lg p-8">
                <div class="grid md:grid-cols-2 gap-8">
                    <div>
                        <h4 class="font-bold text-xl mb-4 text-gray-800"><i class="fas fa-cube mr-2"></i>支持多种格式</h4>
                        <p class="text-gray-600 mb-4">框架应支持多种序列化格式，如 Protobuf、JSON、Thrift，允许开发者根据需求选择。Protobuf 是首选，因其高效、紧凑，适用于大规模分布式系统。</p>
                    </div>
                    <div>
                        <h4 class="font-bold text-xl mb-4 text-gray-800"><i class="fas fa-puzzle-piece mr-2"></i>兼容性</h4>
                        <p class="text-gray-600">在序列化和反序列化过程中，要考虑到版本兼容问题，确保服务端和客户端的不同版本之间能够互相通信。</p>
                    </div>
                </div>
            </div>
        </div>

        <!-- Service Registry -->
        <div class="mb-16">
            <h3 class="section-title text-3xl font-bold mb-8 text-gray-800">服务注册与发现</h3>
            <div class="grid md:grid-cols-3 gap-6">
                <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                    <i class="fas fa-server text-4xl feature-icon mb-4"></i>
                    <h4 class="font-bold text-lg mb-2 text-gray-800">服务注册中心</h4>
                    <p class="text-gray-600 text-sm">设计服务注册中心，可采用 Eureka、Zookeeper、Consul 或自定义。服务启动时自动注册，停止时自动注销。</p>
                </div>
                <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                    <i class="fas fa-memory text-4xl feature-icon mb-4"></i>
                    <h4 class="font-bold text-lg mb-2 text-gray-800">客户端缓存</h4>
                    <p class="text-gray-600 text-sm">客户端缓存服务实例信息，在服务发现延迟或注册中心不可用时仍能正常调用。</p>
                </div>
                <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                    <i class="fas fa-heartbeat text-4xl feature-icon mb-4"></i>
                    <h4 class="font-bold text-lg mb-2 text-gray-800">健康检查</h4>
                    <p class="text-gray-600 text-sm">服务注册中心支持健康检查，定期检查服务实例的可用性，确保客户端只调用健康的实例。</p>
                </div>
            </div>
        </div>

        <!-- Service Governance -->
        <div class="mb-16">
            <h3 class="section-title text